#include "GameMethodSelectScene.h"

#include "TYBase.h"
#include "TYController.h"
#include "TYSounder.h"

GameMethodSelectScene::GameMethodSelectScene(void)
{
}

GameMethodSelectScene::~GameMethodSelectScene(void)
{
}

bool GameMethodSelectScene::init ()
{
	bool bRet = false;

	do
	{
		CCSize s = CCDirector::sharedDirector()->getWinSize();
		CC_BREAK_IF(!CCScene::init());

		GameMethodSelectLayer* layer = GameMethodSelectLayer::node();
		CC_BREAK_IF(!layer);
		this->addChild(layer, 1);

		bRet = true;

	}while(0);

	return bRet;
}

GameMethodSelectLayer::GameMethodSelectLayer()
{

}

GameMethodSelectLayer::~GameMethodSelectLayer()
{

}

bool GameMethodSelectLayer::init ()
{
	bool bRet = false;

	do 
	{
		CCSize s = CCDirector::sharedDirector ()->getWinSize ();

		CC_BREAK_IF(!CCLayerColor::initWithColorWidthHeight (ccc4(0, 0, 0, 255), s.width, s.height));

		CCLabelBMFont* label = CCLabelBMFont::labelWithString(g_gamemenus[MethodA].c_str(), s_fontmenu);
		CC_BREAK_IF(!label);
		CCMenuItemLabel* methodALabel = CCMenuItemLabel::itemWithLabel(label, this, menu_selector(GameMethodSelectLayer::MenuCallBack));
		CC_BREAK_IF(!methodALabel);
		methodALabel->setTag(MethodA);
		methodALabel->setPosition(ccp(s.width/2,s.height/2+120));

		CCLabelBMFont* labelB = CCLabelBMFont::labelWithString(g_gamemenus[MethodB].c_str(), s_fontmenu);
		CC_BREAK_IF(!labelB);
		CCMenuItemLabel* methodBLabel = CCMenuItemLabel::itemWithLabel(labelB, this, menu_selector(GameMethodSelectLayer::MenuCallBack));
		CC_BREAK_IF(!methodBLabel);
		methodBLabel->setTag(MethodB);
		methodBLabel->setPosition(ccp(s.width/2,s.height/2+60));

		CCLabelBMFont* labelC = CCLabelBMFont::labelWithString(g_gamemenus[MethodC].c_str(), s_fontmenu);
		CC_BREAK_IF(!labelC);
		CCMenuItemLabel* methodCLabel = CCMenuItemLabel::itemWithLabel(labelC, this, menu_selector(GameMethodSelectLayer::MenuCallBack));
		CC_BREAK_IF(!methodCLabel);
		methodCLabel->setTag(MethodC);
		methodCLabel->setPosition(ccp(s.width/2,s.height/2));

		CCLabelBMFont* labelBack = CCLabelBMFont::labelWithString(g_gamemenus[GoBack].c_str(), s_fontmenu);
		CC_BREAK_IF(!labelBack);
		CCMenuItemLabel* backLabel = CCMenuItemLabel::itemWithLabel(labelBack, this, menu_selector(GameMethodSelectLayer::MenuCallBack));
		CC_BREAK_IF(!backLabel);
		backLabel->setTag(GoBack);
		backLabel->setPosition(ccp(s.width/2,s.height/2-60));

		CCMenu* menu = CCMenu::menuWithItems(methodALabel,methodBLabel,methodCLabel,backLabel,NULL);
		CC_BREAK_IF(!menu);
		menu->setPosition(CCPointZero);
		menu->setScale(g_fLabelScale);

		this->addChild(menu,1);

		bRet=true;

	} while (0);

	return bRet;
}

void GameMethodSelectLayer::MenuCallBack ( CCObject* sender )
{
	CCMenuItemLabel* tempMenuLabel = (CCMenuItemLabel*)sender;
	if (!tempMenuLabel)
	{
		return;
	}

	TYSounder::shareSounder()->playClickSound();

	switch (tempMenuLabel->getTag())
	{
		case MethodA:
			TYController::ShowMethodPlayScene();
			break;
		case MethodB:
			break;
		case MethodC:
			break;
		case GoBack:
			TYController::ShowMainMenuScene ();
			break;
	}
}